package com.twu.biblioteca.model.menu;

import com.twu.biblioteca.model.item.exceptions.InexistantItemException;

import java.util.Map;
import java.util.TreeMap;

/**
 * Created with IntelliJ IDEA.
 * User: cschlumb
 * Date: 08/08/2013
 * Time: 09:47
 * To change this template use File | Settings | File Templates.
 */
public class Menu {

    private final Map<Integer, IMenu> publicMenu = new TreeMap<Integer, IMenu>();
    private final Map<Integer, IMenu> privateMenu = new TreeMap<Integer, IMenu>();


    public void addPublicItem(int i, IMenu item) {
        publicMenu.put(i, item);
    }

    public IMenu getPublicItem(int i) throws InexistantItemException {
        if (!publicMenu.containsKey(i))
            throw new InexistantItemException();

        return publicMenu.get(i);
    }

    public void addPrivateItem(int i, IMenu item) {
        privateMenu.put(i, item);
    }

    public IMenu getPrivateItem(int i) throws InexistantItemException {
        if (!privateMenu.containsKey(i))
            throw new InexistantItemException();

        return privateMenu.get(i);
    }

    public void formatPublicList(MenuFormatter menuFormatter){
        for (Map.Entry<Integer, IMenu> entry : publicMenu.entrySet()){
            menuFormatter.add(entry.getKey(), entry.getValue());
        }
    }

    public void formatPrivateList(MenuFormatter menuFormatter){
        for (Map.Entry<Integer, IMenu> entry : privateMenu.entrySet()){
            menuFormatter.add(entry.getKey(), entry.getValue());
        }
    }

}
